﻿
@{
    Layout = "~/Views/Shared/_AddEdit.cshtml";
}

@section header{
    <script type="text/javascript">
        function SaveBeforeCallBack() {
            if ($("#_FlowingType").val() == '') {
                layer.msg('温馨提示：必须选择流水类型~！~'); return true;
            }
            if ($("#_FlowingType").val().substring(3, 5) == "01" && $("#_cid").val() == '') {
                layer.msg('温馨提示：选择客户类流水类型时必须填写客户信息~！~'); return true;
            }
            if ($("#_FlowingType").val().substring(0, 3) == "002" && ($("#_RefundId").val() == '' || $("#_RefundId").val() == '0')) {
                layer.msg('温馨提示：选择退费时必须原收费信息~！~'); return true;
            }
            if ($("#_FlowingType").val().substring(0, 3) == "002" && Math.abs($("#_Account").val()) > $("#Tfyje").val()) { layer.msg('温馨提示：退费金额不能大于原金额~！~'); return true; }
            if ($("#_FlowingType").val().substring(3, 5) == "02" && $("#_cid").val() == '') {
                layer.msg('温馨提示：选择合同类流水类型时必须填写客户信息及合同信息~！~'); return true;
            }
            if ($("#_Account").val() == '') {
                layer.msg('温馨提示：必须输入金额~！~'); return true;
            }
            if ($("#_AccountMode").val() == '') {
                layer.msg('温馨提示：必须选择资金来源~！~'); return true;
            }
            var je = parseFloat($("#_Account").val());

            var fje = -je;
            //if ($("#_FlowingType").val() == "00202001")
            //{
            //    var htje = parseFloat($("#_HtSjje").val());
            //    if (htje + fje != 0) { layer.msg('温馨提示：选择退费时金额必须一次性退完~！~' + htje); return true; }
            //}
            if (@ViewBag.Customer> 0) {
                if ($("#_AccountType").val() != "收入类" && je > 0)
                    $("#_Account").val(fje);
            }
            else {
                if ($("input[name='_AccountType']:checked").val() != "收入类" && je > 0)
                    $("#_Account").val(fje);
            }
            if (@ViewBag.data["state"]> 0 && @ViewBag.Lx == 1) { layer.msg("已入帐不可修改!"); return true; }

            $("#_CreateDate").val("@System.DateTime.Now");


        }



    </script>
}
<input type="hidden" name="_RefundId" id="_RefundId" value="@ViewBag.data["RefundId"]" />
<input type="hidden" name="htysje" id="htysje" value="@ViewBag.htysje" />
<input type="hidden" name="Tfyje" id="Tfyje" value="@ViewBag.Tfyje" />

<input type="hidden" name="_LeagueId" id="_LeagueId" value="@ViewBag.data["LeagueId"]" />
<input type="hidden" name="_state" id="_state" value="@ViewBag.data["state"]" />
<input type="hidden" name="_CreateId" id="_CreateId" value="@ViewBag.data["CreateId"]" />
<input type="hidden" name="_ContractId" id="_ContractId" value="@ViewBag.data["ContractId"]" />
<input type="hidden" name="_AchievementId" id="_AchievementId" value="@ViewBag.data["AchievementId"]" />
<input type="hidden" name="_CreateDate" id="_CreateDate" value="@ViewBag.data["CreateDate"]" />
<input type="hidden" name="_cid" id="_cid" value="@ViewBag.data["cid"]" />
<input type="hidden" name="_guid" id="_guid" value="@ViewBag.data["guid"]" />
<input type="hidden" name="_ImageUrl" id="_ImageUrl" value="@ViewBag.data["ImageUrl"]" />
<input type="hidden" name="_activityId" id="_activityId" value="@ViewBag.data["activityId"]" />
<input type="hidden" name="_FollowUPId" id="_FollowUPId" value="@ViewBag.data["FollowUPId"]" />
<input type="hidden" name="_HtSfje" id="_HtSfje" />
<input type="hidden" name="_HtSjje" id="_HtSjje" />
<div class="layui-card-body">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-row layui-col-space1">
            @if (ViewBag.Customer == 0)
            {
                <div class="layui-col-md6">

                    <div class="layui-card">
                        <div class="layui-form-item">
                            <label class="layui-form-label">帐目类型</label>
                            <div class="layui-input-inline">
                                <input type="radio" name="_AccountType" lay-filter="AccountType" value="收入类" title="收入类" @(ViewBag.data["AccountType"] == "收入类" ? "checked='checked'" : "")>
                                <input type="radio" name="_AccountType" lay-filter="AccountType" value="支出类" title="支出类" @(ViewBag.data["AccountType"] == "支出类" ? "checked='checked'" : "")>
                                <input type="radio" name="_AccountType" lay-filter="AccountType" value="预算" title="预算" @(ViewBag.data["AccountType"] == "预算" ? "checked='checked'" : "")>
                            </div>
                        </div>
                        <div class="layui-form-item">

                            <label class="layui-form-label" id="lxxz">流水类型</label>
                            <div class="layui-input-inline">
                                <select lay-verify="required" name="_FlowingType" lay-filter="FlowingType" id="_FlowingType">
                                    <option value=""></option>
                                    @foreach (var data in ViewBag.FlowingType.Rows)
                                    {

                                        <option value="@data["did"]" @(ViewBag.data["FlowingType"] == @data["did"] ? "selected" : "")>@data["dname"]</option>
                                    }

                                </select>

                            </div>

                        </div>
                        <div class="layui-form-item" id="xyxx" style="display:none;">
                            <label class="layui-form-label">选择客户</label>
                            <div class="layui-input-inline">
                                <input type="text" id="CusDisplay" placeholder="手机号码" class="layui-input">
                                <input type="text" id="HdDisplay" placeholder="活动名称" style="display:none;" class="layui-input">

                            </div>  <a class="layui-btn " href="#" onclick="searchCus()"><i class="layui-icon">&#xe615;</i></a>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label" id="je">金额</label>
                            <div class="layui-input-inline">
                                <input type="text" name="_Account" id="_Account" value="@ViewBag.data["Account"]" required lay-verify="number" placeholder="请输入金额" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>


                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">日期</label>
                            <div class="layui-input-inline">
                                <input type="text" name="_ADate" id="BirdDate" value="@ViewBag.data["ADate"]" required lay-verify="required" placeholder="请选择日期" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label" id="zjly">资金来源 </label>
                            <div class="layui-input-inline">
                                <select name="_AccountMode" id="_AccountMode" lay-verify="required">
                                    <option value=""></option>
                                    @foreach (var data in ViewBag.AccountMode.Rows)
                                    {

                                        <option value="@data["did"]" @(ViewBag.data["AccountMode"] == @data["did"] ? "selected" : "")>@data["dname"]</option>
                                    }
                                </select>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="layui-col-md6">
                    <div class="layui-card" id="Khxx" style="display:none;">
                        <fieldset class="layui-elem-field layui-field-title">
                            <legend>客户信息</legend>
                        </fieldset>
                        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                            <ul class="layui-tab-title">
                                <li class="layui-this" lay-id="khzyxx">客户摘要</li>
                                <li>收费明细</li>
                                <li>合同明细</li>
                                <li>活动明细</li>
                                <li>试听未收</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <div id="xy">
                                        <table class="layui-table" style="width:700px;">
                                            <tbody>
                                                <tr>
                                                    <td>信息</td>
                                                    <td>
                                                        <div id="BB"></div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>订金</td>
                                                    <td>
                                                        <div id="Djzy"></div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>合同</td>
                                                    <td>    <div id="Htzy"></div></td>
                                                </tr>
                                                <tr>
                                                    <td>活动</td>
                                                    <td>
                                                        <div id="Hdzy"></div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>动态</td>
                                                    <td style="padding-bottom: 0;">
                                                        <div id="dt"></div>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Rydjtable" id="Rydjtable"></table></div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Ryhttable" id="Ryhttable"></table></div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Ryhdtable" id="Ryhdtable"></table></div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Rysttable" id="Rysttable"></table></div>
                            </div>
                        </div>

                    </div>
                </div>
            }
            else
            {
                <input type="hidden" name="_AccountType" id="_AccountType" value="@ViewBag.data["AccountType"]" />
                <input type="hidden" name="_FlowingType" id="_FlowingType" value="@ViewBag.data["FlowingType"]" />

                <div class="layui-form-item">
                    <label class="layui-form-label" id="je">金额</label>
                    <div class="layui-input-inline">
                        <input type="text" name="_Account" id="_Account" value="@ViewBag.htysje" required lay-verify="number" placeholder="请输入金额" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>


                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="_ADate" id="BirdDate" value="@ViewBag.data["ADate"]" required lay-verify="required" placeholder="请选择日期" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" id="zjly">资金来源 </label>
                    <div class="layui-input-inline">
                        <select name="_AccountMode" id="_AccountMode" lay-verify="required">
                            <option value=""></option>
                            @foreach (var data in ViewBag.AccountMode.Rows)
                            {

                                <option value="@data["did"]" @(ViewBag.data["AccountMode"] == @data["did"] ? "selected" : "")>@data["dname"]</option>
                            }
                        </select>
                    </div>
                </div>

            }
            <div class="layui-form-item ">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                    <legend>上传凭证</legend>
                </fieldset>

                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="test2">凭证上传</button>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        预览图：
                        <div class="layui-upload-list" id="demo2"></div>
                    </blockquote>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <textarea name="_Remark" placeholder="请输入内容" class="layui-textarea" style="min-height:100px;min-width:300px;">@ViewBag.data["Remark"]</textarea>
                </div>
            </div>
            <div id="xyselect"><table class="layui-table" lay-skin="line" lay-filter="demo" id="demo"></table></div>

        </div>
    </form>
</div>



<script>

    layui.use('laydate', function () {
        var laydate = layui.laydate;


        laydate.render({
            elem: '#BirdDate'
            , value: new Date()
        });

    });
    layui.use('upload', function () {
        var upload = layui.upload;

        //多图片上传
        upload.render({
            elem: '#test2'
            , url: '../Contract/ContractList/Upload?DirName=At/upload/'
            , multiple: true
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" width="200px" height="150px" class="layui-upload-img"> ')
                });
            }
            , done: function (res) {
                //上传完毕
                if (res.code == 0) { //上传成功

                    if ($("#_ImageUrl").val() == "") {
                        $("#_ImageUrl").val(res.data.src);

                    }
                    else {
                        $("#_ImageUrl").val($("#_ImageUrl").val() + ',' + res.data.src);

                    }

                }
            }
        });

    });
    function csh() {
        $("#_AchievementId").val('');
        $("#_cid").val('');
        $("#_ContractId").val('');
        $("#_activityId").val('');
        $("#Khxx").css('display', 'none');
        $("#xyxx").css('display', 'none');
        $("#Rydjtable").html('');
        $("#Ryhttable").html('');
        $("#Ryhdtable").html('');
        $("#HdDisplay").val('');
    }
    layui.use('form', function () {
        var form = layui.form;
        form.on('radio(AccountType)', function (data) {

            csh();
            if (data.value == "收入类") $("#_state").val("2");
            else
                $("#_state").val("0");
            $.ajax({
                url: "../Account/At/FlowingTypeData",
                dataType: "json",
                data: {
                    type: "@ViewBag.type",
                    id: "@ViewBag.id",
                    keyCode:"@ViewBag.keyCode",
                    lxmc: data.value,
                    t: new Date().getTime()
                },
                success: function (data) {

                    if (data.code = "0000") {
                        $('#_FlowingType').html("");
                        var t = '<option value="">请选择类型</option>';
                        for (var i = 0; i < data.data.length; i++) {
                            t += ' <option value="' + data.data[i].did + '" >' + data.data[i].dname + '</option > ';
                        }
                        $('#_FlowingType').append(t);
                        form.render('select');
                    }
                }


            });

        });

        form.on('select(FlowingType)', function (data) {
            csh();
            if (data.value.substring(3, 5) == "01" || data.value.substring(3, 5) == "02" || data.value.substring(3, 5) == "04") {
                $("#xyxx").css('display', '');
                $("#HdDisplay").css('display', 'none');
                $("#HdDisplay").val('');
            }
            else if (data.value.substring(3, 5) == "03") {
                $("#xyxx").css('display', '');
                $("#HdDisplay").css('display', '');
            }
            else {
                $("#xyxx").css('display', 'none');
                $("#HdDisplay").css('display', 'none');
                $("#HdDisplay").val('');
            }


        });
    })

    function searchCus() {
        var indexs;
          if (@ViewBag.Lx== 0)
             indexs = layer.load();
        var UrlCs = "../Account/At/Data";
        var UrlValue = $("#CusDisplay").val();

        var column = [[{ field: 'id', title: 'ID', width: 60, sort: true }, { field: 'CustName', title: '宝宝姓名', width: 100 }, { field: 'ChildName', title: '小名', Width: 80 }, { field: 'LinkName', title: '联系人', Width: 80 }, { field: 'CustTel', title: '联系电话', minwidth: 100 }, { field: 'LinkRelation', title: '关系', width: 80 }]];
        if ($("#HdDisplay").val() != "") {
            UrlCs = "../Account/At/HdData";
            UrlValue = $("#HdDisplay").val();
            column = [[{ field: 'id', title: 'ID', width: 60, sort: true }, { field: 'ActivityName', title: '活动名称', width: 100 }, { field: 'ChargeName', title: '负责人', Width: 80 }, { field: 'ActAddress', title: '活动地址', Width: 120 }, { field: 'tel', title: '联系电话', minwidth: 100 }, { field: 'MPrice', title: '会员价', width: 80 }, { field: 'NoMPrice', title: '非会员价', width: 80 }]];
        }
        if (@ViewBag.Lx== 1) {
            try {
                if ("@ViewBag.data["activityId"]"> 0) {
                    UrlCs = "../Account/At/HdData"; UrlValue = $("#HdDisplay").val();
                    column = [[{ field: 'id', title: 'ID', width: 60, sort: true }, { field: 'ActivityName', title: '活动名称', width: 100 }, { field: 'ChargeName', title: '负责人', Width: 80 }, { field: 'ActAddress', title: '活动地址', Width: 120 }, { field: 'tel', title: '联系电话', minwidth: 100 }, { field: 'MPrice', title: '会员价', width: 80 }, { field: 'NoMPrice', title: '非会员价', width: 80 }]];

                }
                throw 'someError';
       }
            catch (err) { }
        }

      $.ajax({
          url: UrlCs,
        dataType:"json",
        data: {
            type:"@ViewBag.type",
            id:"@ViewBag.id",
            keyCode: "@ViewBag.KeyCode",
            Tel: UrlValue,
            khid:@ViewBag.Customer,
            t:new Date().getTime()
        },
          success: function (data) {
               if (@ViewBag.Lx== 0)
              layer.close(indexs);
            if (data.code == "0000") {
                var json = eval(data.data); //数组
                if (json.length == 1) {
                    $("#Khxx").css('display', '');
                    if(@ViewBag.Lx== 0)
                    $("#_AchievementId").val(json[0].LatelyReceId);
                    if ($("#_FlowingType").val().substring(3, 5) == "01"&&@ViewBag.Lx== 0) {
                        $("#_ContractId").val('');
                        $("#_activityId").val('');
                        $("#_cid").val(json[0].id);

                    }
                    else if ($("#_FlowingType").val().substring(3, 5) == "02"&&@ViewBag.Lx== 0) {
                        $("#_ContractId").val(json[0].ContractId);
                        $("#_cid").val(json[0].id);
                        $("#_activityId").val('');
                        $("#dt").html(json[0].Htxx);
                        $("#_Account").val(json[0].Htysje);
                        $("#_HtSfje").val(json[0].HtSfje);
                        $("#_HtSjje").val(json[0].DisPrice );


                    }
                    else if ($("#_FlowingType").val().substring(3, 5) == "03"&&@ViewBag.Lx== 0) {
                        $("#_ContractId").val('');
                        $("#_activityId").val(json[0].ActivityId);
                        $("#_cid").val(json[0].id);
                        $("#dt").html(json[0].Hdxx);
                        $("#_Account").val(json[0].Hdysje);


                    }
                    else if ($("#_FlowingType").val().substring(3, 5) == "04"&&@ViewBag.Lx== 0) {
                        $("#_ContractId").val('');
                        $("#_FollowUPId").val(json[0].UpId);
                        $("#_cid").val(json[0].id);
                        $("#dt").html(json[0].Upmx);

                    }
                    if ($("#HdDisplay").val() == "") {
                        if (@ViewBag.Lx== 1) {
                            try {
                                if ('@ViewBag.data["activityId"]' > '0') {
                                    $("#xy").html("活动名称：" + json[0].ActivityName + "  负责人：" + json[0].ChargeName + " 会员价：<span class=\"layui-badge \" >" + json[0].MPrice + "</span> 非会员价：<span class=\"layui-badge layui-bg-orange \" >" + json[0].NoMPrice + "</span> 负责人：" + json[0].ChargeName + " 联系电话：" + json[0].tel);
                                }
                                else {
                                    if (json[0].Sex == "男")
                                        $("#BB").html("<i class=\"layui-icon layui-icon-male\" style=\"color:bule;\"></i>宝宝姓名：" + json[0].CustName + " 宝宝小名：" + json[0].ChildName + " 联系人：" + json[0].LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + json[0].CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + json[0].UserName + "</span>");
                                    else
                                        $("#BB").html("<i class=\"layui-icon layui-icon-male\"  style=\"color:#FF69B4;\"></i>宝宝姓名：" + json[0].CustName + " 宝宝小名：" + json[0].ChildName + " 联系人：" + json[0].LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + json[0].CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + json[0].UserName + "</span>");
                                    $("#Djzy").html("订金金额：" + json[0].Djje + " 其中未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].DjWrzJe + "</span> 已入账：" + json[0].DjWsyJe + " 已使用：" + json[0].DjYsyJe + " 已作废：" + json[0].DjZfJe);
                                    $("#Htzy").html("合同金额：" + json[0].Htje + " 合同实收：" + json[0].HtSsje + " 其中未计费：<span class=\"layui-badge \" >" + json[0].HtWjfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].HtWrzJe + "</span> 已入账：" + json[0].HtRzJe + " 已退费：" + json[0].HtTfJe);
                                    $("#Hdzy").html("参加活动次数：" + json[0].Hdsl + "  金额：" + json[0].Hdje + " 其中未收费：<span class=\"layui-badge \" >" + json[0].HdWsfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].HdWrzJe + "</span> 已入账：" + json[0].HdYrzJe + " 已退费：" + json[0].HdTfJe);

                                    GetTable(json[0].id);
                                }
                                throw 'someError';
                            }
                            catch (err) {
                                if (json[0].Sex == "男")
                                    $("#BB").html("<i class=\"layui-icon layui-icon-male\" style=\"color:bule;\"></i>宝宝姓名：" + json[0].CustName + " 宝宝小名：" + json[0].ChildName + " 联系人：" + json[0].LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + json[0].CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + json[0].UserName + "</span>");
                                else
                                    $("#BB").html("<i class=\"layui-icon layui-icon-male\"  style=\"color:#FF69B4;\"></i>宝宝姓名：" + json[0].CustName + " 宝宝小名：" + json[0].ChildName + " 联系人：" + json[0].LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + json[0].CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + json[0].UserName + "</span>");
                                $("#Djzy").html("订金金额：" + json[0].Djje + " 其中未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].DjWrzJe + "</span> 已入账：" + json[0].DjWsyJe + " 已使用：" + json[0].DjYsyJe + " 已作废：" + json[0].DjZfJe);
                                $("#Htzy").html("合同金额：" + json[0].Htje + " 合同实收：" + json[0].HtSsje + " 其中未计费：<span class=\"layui-badge \" >" + json[0].HtWjfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].HtWrzJe + "</span> 已入账：" + json[0].HtRzJe + " 已退费：" + json[0].HtTfJe);
                                $("#Hdzy").html("参加活动次数：" + json[0].Hdsl + "  金额：" + json[0].Hdje + " 其中未收费：<span class=\"layui-badge \" >" + json[0].HdWsfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].HdWrzJe + "</span> 已入账：" + json[0].HdYrzJe + " 已退费：" + json[0].HdTfJe);

                                GetTable(json[0].id); }
                        }
                        else {
                            if (json[0].Sex == "男")
                                $("#BB").html("<i class=\"layui-icon layui-icon-male\" style=\"color:bule;\"></i>宝宝姓名：" + json[0].CustName + " 宝宝小名：" + json[0].ChildName + " 联系人：" + json[0].LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + json[0].CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + json[0].UserName + "</span>");
                            else
                                $("#BB").html("<i class=\"layui-icon layui-icon-male\"  style=\"color:#FF69B4;\"></i>宝宝姓名：" + json[0].CustName + " 宝宝小名：" + json[0].ChildName + " 联系人：" + json[0].LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + json[0].CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + json[0].UserName + "</span>");
                            $("#Djzy").html("订金金额：" + json[0].Djje + " 其中未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].DjWrzJe + "</span> 已入账：" + json[0].DjWsyJe + " 已使用：" + json[0].DjYsyJe + " 已作废：" + json[0].DjZfJe);
                            $("#Htzy").html("合同金额：" + json[0].Htje + " 合同实收：" + json[0].HtSsje + " 其中未计费：<span class=\"layui-badge \" >" + json[0].HtWjfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].HtWrzJe + "</span> 已入账：" + json[0].HtRzJe + " 已退费：" + json[0].HtTfJe);
                            $("#Hdzy").html("参加活动次数：" + json[0].Hdsl + "  金额：" + json[0].Hdje + " 其中未收费：<span class=\"layui-badge \" >" + json[0].HdWsfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].HdWrzJe + "</span> 已入账：" + json[0].HdYrzJe + " 已退费：" + json[0].HdTfJe);

                            GetTable(json[0].id);
                        }


                    }
                    else {
                        $("#xy").html("活动名称：" + json[0].ActivityName + "  负责人：" + json[0].ChargeName + " 会员价：<span class=\"layui-badge \" >" + json[0].MPrice + "</span> 非会员价：<span class=\"layui-badge layui-bg-orange \" >" + json[0].NoMPrice + "</span> 负责人：" + json[0].ChargeName + " 联系电话：" + json[0].tel);
                    }

                    $("#xyselect").css('display', 'none');


                }
                else if (json.length > 1) {

                    $("#xyselect").css('display', '');
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.open({
                            title: '请选择人员信息',
                            type: 1,
                            shadeClose: true,
                            area: ['700px', '500px'],
                            content: $("#xyselect").html("<table class=\"layui - table\" lay-skin=\"line\" lay-filter=\"demo\" id=\"demo\"></table>"),
                            cancel: function (index, layero) { $("#xyselect").html(''); },
                            end: function (index, layero) { $("#xyselect").html(''); }
                        });
                    })
                    layui.use('table', function () {
                     var table = layui.table;
                    table.render({
                        elem: '#demo'
                        , cols: column
                        , data: data.data
                       ,skin: 'line' //表格风格
                        , even: true
                        ,page: true //是否显示分页

                        , limit: 10//每页默认显示的数量

                        });
                        table.on('row(demo)', function (obj) {

                            var data = obj.data;
                            $("#Khxx").css('display', '');
                            $("#_AchievementId").val(data.LatelyReceId);
                            if ($("#_FlowingType").val().substring(3, 5) == "01") {
                                $("#_ContractId").val('');
                                $("#_activityId").val('');
                                $("#_cid").val(data.id);

                            }
                            else if ($("#_FlowingType").val().substring(3, 5) == "02") {
                                $("#_ContractId").val(data.ContractId);
                                $("#_cid").val(data.id);
                                $("#_activityId").val('');
                                $("#_Account").val(data.Htysje);
                                $("#_HtSfje").val(data.HtSfje);
                                $("#_HtSjje").val(data.DisPrice);
                                $("#dt").html(data.Htxx);

                            }
                            else if ($("#_FlowingType").val().substring(3, 5) == "03") {
                                $("#_ContractId").val('');
                                $("#_activityId").val(data.ActivityId);
                                $("#_cid").val(data.id);
                                $("#_Account").val(data.Hdysje);
                                $("#dt").html(data.Hdxx);
                            }
                            else if ($("#_FlowingType").val().substring(3, 5) == "04") {
                                $("#_ContractId").val('');
                                $("#_FollowUPId").val(data.UpId);
                                $("#_cid").val(data.id);
                                $("#dt").html(data.Upmx);
                            }
                            if ($("#HdDisplay").val() == "") {
                                if (data.Sex == "男")
                                    $("#BB").html("<i class=\"layui-icon layui-icon-male\" style=\"color:bule;\"></i>宝宝姓名：" + data.CustName + " 宝宝小名：" + data.ChildName + " 联系人：" + data.LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + data.CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + data.UserName + "</span>");
                                else
                                    $("#BB").html("<i class=\"layui-icon layui-icon-male\"  style=\"color:#FF69B4;\"></i>宝宝姓名：" + data.CustName + " 宝宝小名：" + data.ChildName + " 联系人：" + data.LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + data.CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + data.UserName + "</span>");
                                $("#Djzy").html("订金金额：" + data.Djje + " 其中未入账：<span class=\"layui-badge layui-bg-orange \" >" + data.DjWrzJe + "</span> 已入账：" + data.DjWsyJe + " 已使用：" + data.DjYsyJe + " 已作废：" + data.DjZfJe);
                                $("#Htzy").html("合同金额：" + data.Htje + " 合同实收：" + data.HtSsje + " 其中未计费：<span class=\"layui-badge \" >" + data.HtWjfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + data.HtWrzJe + "</span> 已入账：" + data.HtRzJe + " 已退费：" + data.HtTfJe);
                                $("#Hdzy").html("参加活动次数：" + data.Hdsl + "  金额：" + data.Hdje + " 其中未收费：<span class=\"layui-badge \" >" + data.HdWsfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + data.HdWrzJe + "</span> 已入账：" + data.HdYrzJe + " 已退费：" + data.HdTfJe);

                                GetTable(data.id);
                            }
                            else {
                                $("#xy").html("活动名称：" + data.ActivityName + "  负责人：" + data.ChargeName + " 会员价：<span class=\"layui-badge \" >" + data.MPrice + "</span> 非会员价：<span class=\"layui-badge layui-bg-orange \" >" + data.NoMPrice + "</span> 负责人：" + data.ChargeName + " 联系电话：" + data.tel);
                            }
                            layer.closeAll();
                            $("#xyselect").html('');
                        });

                    });
                }
                else {
                    $("#xy").html("未找到学员信息");
                    $("#_cid").val("");
                    $("#_AchievementId").val("");
                    $("#_ContractId").val('');
                    $("#_activityId").val('');
                    $("#_FollowUPId").val('');
                    $("#xyselect").css('display', 'none');
                }

            }

        }
    });
    }
    function GetTable(id)
    {
                     var djUrl = "../Account/At/DjData";
                    var HtUrl = "../Account/At/RyHtData";
        var HdUrl = "../Account/At/RyHdData";
        var stUrl = "../Account/At/StData";
                    layui.use('table', function () {
                        var table = layui.table;
                        table.render({
                            elem: '#Rydjtable'
                            , url: djUrl //数据接口
                            , where: { keyCode: "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id",Cid:id, t: new Date().getTime() }
                            , width: 580
                            , limit:5
                            , page: true //是否显示分页
                            , parseData: function (res) {
                                return {
                                    "code": res.code,
                                    "msg": res.message,
                                    "count": res.data.count,
                                    "data": res.data.data
                                };
                            }
                            , totalRow: true

                            , cols: [[ //标题栏
                                { field: 'FlowingName', title: '渠道', width: 80, totalRowText: '合计' }
                                , { field: 'ModeName', title: '流水类型', Width:130 }
                                , { field: 'Account', title: '金额', Width: 60, totalRow: true }
                                , { field: 'ADate', title: '操作日期', width: 130 }
                                , { field: 'AchName', title: '业绩所属', width: 80 }
                                , { field: 'stateName', title: '状态', width: 80 }
                            ]]

                            , skin: 'line' //表格风格
                            , even: true

                        });


                         table.render({
                             elem: '#Ryhttable'
                            , url: HtUrl //数据接口
                            , where: { keyCode: "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id",Cid:id, t: new Date().getTime() }
                             , width: 1050
                             , totalRow: true
                             , parseData: function (res) {
                                 return {
                                     "code": res.code,
                                     "msg": res.message,
                                     "count": res.data.count,
                                     "data": res.data.data
                                 };
                             }
                             , cols: [[ //标题栏
                                 { field: 'contractNumber', title: '合同编号' }
                                 , { field: 'SetmealName', title: '套餐名称' }
                                 , { field: 'je', title: '已收/实收/金额', width:190 }
                                 , { field: 'ConDate', title: '合同日期', width:190  }
                                 , { field: 'CourseDate', title: '执行日期'}
                                 , { field: 'CreateDate', title: '创建日期', width: 110  }
                                 , { field: 'AchName', title: '业绩所属' }
                                 , { field: 'stateName', title: '合同状态' }
                                 , { field: 'stateName', title: '收费状态' }
                             ]]

                            , skin: 'line' //表格风格
                            , even: true
                            , page: true //是否显示分页

                            , limit: 5//每页默认显示的数量

                        });
                           table.render({
                               elem: '#Rysttable'
                            , url: stUrl //数据接口
                            , where: { keyCode: "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id",Cid:id, t: new Date().getTime() }
                             , width: 750

                             , parseData: function (res) {
                                 return {
                                     "code": res.code,
                                     "msg": res.message,
                                     "count": res.data.count,
                                     "data": res.data.data
                                 };
                             }
                            , cols: [[ //标题栏
                                { field: 'MakeDate', title: '日期', width: 100}
                                , { field: 'CourseName', title: '试听课程', Width:130 }
                                , { field: 'Remark', title: '备注', Width:150 }
                                , { field: 'TeacherName', title: '老师', width: 80  }
                                , { field: 'TwoTeacherName', title: '辅助老师', width:80 }

                            ]]

                            , skin: 'line' //表格风格
                            , even: true
                            , page: true //是否显示分页

                            , limit: 5//每页默认显示的数量

                        });


                        table.render({
                             elem: '#Ryhdtable'
                            , url: HdUrl //数据接口
                            , where: { keyCode:  "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id",Cid:id, t: new Date().getTime() }
                            , width: 430
                            , totalRow: true
                            , parseData: function (res) {
                                return {
                                    "code": res.code,
                                    "msg": res.message,
                                    "count": res.data.count,
                                    "data": res.data.data
                                };
                            }
                            , cols: [[ //标题栏
                                { field: 'Id', title: 'ID', width: 80,totalRowText: '合计' }
                                , { field: 'DecPrice', title: '金额', Width: 60, totalRow: true }
                                , { field: 'CreateDate', title: '操作日期', width: 130 }
                                , { field: 'ActivityName', title: '业绩所属', width: 80 }
                                , { field: 'stateName', title: '状态', width: 80 }
                            ]]

                            , skin: 'line' //表格风格
                            , even: true
                            , page: true //是否显示分页

                            , limit: 5//每页默认显示的数量

                        });
                        table.on('row(Rydjtable)', function (obj) {

                            var data = obj.data;
                            if ($("#_FlowingType").val().substring(0, 3) == "002") {
                                if ($("#_FlowingType").val().substring(3, 5) == data.flowingtype.substring(3,5))
                                {
                                    if (data.isReturn != "1" && data.Account > "0" && data.state == "2") {
                                        if ($("#_FlowingType").val().substring(3, 5) == "02" && data.htstate== "1")
                                                 layer.msg('温馨提示：合同退费必须选择未到期合同~！~');
                                         else
                                        {
                                            $("#_RefundId").val(data.id);
                                            $("#_ContractId").val(data.ContractId);
                                            $("#_activityId").val(data.activityId);
                                            $("#_FollowUPId").val(data.FollowUPId);
                                            $("#_Account").val(data.Account);
                                            $("#Tfyje").val(data.Account);
                                             $("#dt").html(data.ModeName + "  金额" + data.Account);
                                             var element = layui.element;
                                             element.tabChange('docDemoTabBrief', 'khzyxx');
                                          }
                                    }
                                    else
                                        layer.msg('温馨提示：退费必须选择未退费且已经入账费用~！~');
                                }
                                else
                                    layer.msg('温馨提示：退费必须选择同类型退费~！~');


                            }
                        });
                        table.on('row(Ryhttable)', function (obj) {

                            var data = obj.data;
                            if ($("#_FlowingType").val().substring(3, 5) == "02") {
                                $("#_ContractId").val(data.id);
                                $("#dt").html(data.Htxx);
                                $("#_Account").val(data.Htysje);
                                $("#_HtSfje").val(data.HtSfje);
                                $("#_HtSjje").val(data.DisPrice);
                                var element = layui.element;
                                element.tabChange('docDemoTabBrief', 'khzyxx');
                            }

                        });
                        table.on('row(Ryhdtable)', function (obj) {
                            var data = obj.data;
                            if ($("#_FlowingType").val().substring(3, 5) == "03") {
                                $("#_activityId").val(data.id);

                                $("#dt").html(data.Hdxx);
                                $("#_Account").val(data.Hdysje);
                                var element = layui.element;
                                element.tabChange('docDemoTabBrief', 'khzyxx');
                            }

                        });
                        table.on('row(Rysttable)', function (obj) {
                            var data = obj.data;
                            if ($("#_FlowingType").val().substring(3, 5) == "04") {
                                $("#_FollowUPId").val(data.id);
                                $("#dt").html(data.MakeDate+'课程'+data.CourseName);
                                var element = layui.element;
                                element.tabChange('docDemoTabBrief', 'khzyxx');
                            }

                        });
                    });
    }
</script>
@section fooler{
    <script>
if(@ViewBag.Lx==1)
{

        searchCus();


    if ("@ViewBag.data["ImageUrl"]" != "") {
        var ss = "@ViewBag.data["ImageUrl"]";
        var Images = ss.split(",");
        for (var i = 0; i < Images.length;i++)
            $('#demo2').append('<img src="../UpFile/At/upload/' + Images[i] + '" alt="#" width="200px" height="150px" class="layui-upload-img"> ')
    }
}
    </script>

}